package com.reebake.ideal.protect.handler;

import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.SecureUtil;
import com.reebake.ideal.crypto.entity.SecretKeyEntity;
import com.reebake.ideal.protect.core.ContentSecureService;

/**
 * AES加解密， 默认加密方式为ECB ，默认的填充方式为 PKCS5
 */
public class DefaultContentSecureService implements ContentSecureService {
    @Override
    public String encrypt(String content, SecretKeyEntity secretKeyEntity) {
        byte[] key = Base64.decode(secretKeyEntity.getSecretKey());
        return SecureUtil.aes(key)
                .encryptBase64(content);
    }

    @Override
    public String decrypt(String content, SecretKeyEntity secretKeyEntity) {
        byte[] key = Base64.decode(secretKeyEntity.getSecretKey());
        return SecureUtil.aes(key).decryptStr(content);
    }

}
